package org.fhm.zdte.common.service.message;

import org.fhm.substrate.annotation.BeanEnable;
import org.fhm.substrate.annotation.Component;
import org.fhm.substrate.annotation.Setup;
import org.fhm.substrate.manager.Bootstrap;
import org.fhm.zdte.common.constant.protocol.ContentType;
import org.fhm.zdte.common.pojo.Request;
import org.fhm.zdte.common.pojo.Result;
import org.fhm.zdte.common.standard.IJsonConvertor;

/**
 * TEXT receive message manager.
 *
 * @author 谭波
 * @since 2023/11/16
 */
@Component("TEXT")
public class TextReceiveMessageManager extends AbstractReceiveMessageManager {

    @Setup
    private IJsonConvertor iJsonConvertor;

    public TextReceiveMessageManager() {
        super(ContentType.TEXT);
    }

    @Override
    public Request convert(byte[] content) {
        return iJsonConvertor.fromJson(new String(content, Bootstrap.charset), Result.class);
    }

    @BeanEnable
    private void beanEnable() {
        setLengthOfPacketWithContent();
    }


}
